package com.objetdirect.gwt.umldrawer.server.services;

import java.util.Date;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.objetdirect.gwt.umldrawer.server.dao.NotificationsDao;
import com.objetdirect.gwt.umldrawer.shared.dto.NotificationsDto;
import com.objetdirect.gwt.umldrawer.shared.dto.ProjectDto;
import com.objetdirect.gwt.umldrawer.shared.services.NotificationService;

@Service("notificationService")
public class NotificationServiceImpl implements NotificationService {

	@Autowired
	private NotificationsDao notificationsDao;

	@PostConstruct
	public void init() throws Exception {
	}

	@PreDestroy
	public void distroy() {
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public void addNotification(int projectId, String notificationContent)
			throws Exception {

		ProjectDto project = new ProjectDto(projectId);
		NotificationsDto notification = new NotificationsDto(
				notificationContent, new Date(), new Date(), 1, project);
		notificationsDao.persist(notification);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public List<NotificationsDto> getNotifications(int projectId)
			throws Exception {
		return null;
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public void removeNotifications(int projectId) throws Exception {

	}

}
